﻿using UnityEngine;
using System.Collections;

public class KeepOlder : MonoBehaviour {

	//public string StartTimeString;
	public System.DateTime StartTime;
	// Use this for initialization
	void Start () {
		this.StartTime = System.DateTime.Now;
		//this.StartTimeString = this.StartTime.ToLongTimeString ();
		foreach (GameObject obj in GameObject.FindObjectsOfType(typeof(GameObject))) {
			if (obj.name == this.gameObject.name) {
				KeepOlder older = (KeepOlder)obj.GetComponent(typeof(KeepOlder));
				if (older != null) {
					if (older.StartTime < this.StartTime) {
						Destroy(this.gameObject);
					}
					if (this.StartTime < older.StartTime) {
						Destroy (obj.gameObject);
					}
				}
			}
		}
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
